<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="tableData"
      style="width: 100%;margin-top:10px;"
      ref="multipconstable">
      <el-table-column prop="order_id" label="订单号">
      </el-table-column>
      <el-table-column prop="title" label="商品名">
      </el-table-column>
      <el-table-column prop="account" label="用户手机" width="140px">
      </el-table-column>
      <el-table-column prop="totals" label="支付金额" width="100px">
      </el-table-column>
      <el-table-column label="原价" width="100px">
        <template slot-scope="scope">
            <span>{{ scope.row.active.desc_price }}</span>
          </template>
      </el-table-column>
      <el-table-column label="支付方式" width="100px">
        <template slot-scope="scope">
            <span>{{ scope.row.pay_type == 1 ? '微信支付' : '支付宝' }}</span>
          </template>
      </el-table-column>
      <el-table-column label="支付时间" width="160px">
        <template slot-scope="scope">
            <span>{{ scope.row.pay_time | date }}</span>
          </template>
      </el-table-column>
      <el-table-column label="状态" width="80px">
        <template slot-scope="scope">
          <el-tag size="mini" type="danger" v-if="scope.row.status == 1">待支付</el-tag>
          <el-tag size="mini" type="warning" v-if="scope.row.status == 2">待发货</el-tag>
          <el-tag size="mini" type="success" v-if="scope.row.status == 4">已发货</el-tag>
          </template>
      </el-table-column>
      <!-- <el-table-column label="操作" width="100px">
          <template slot-scope="scope">
            <el-button
              type="text"
              :loading="scope.row.loading"
              @click="handleEdit(scope.$index, scope.row)"
              class="ml-0 mb-1">发货</el-button>
          </template>
        </el-table-column> -->
    </el-table>
  </div>
</template>

<script>
import { list, send } from '../../api/group_order'
export default {
  data() {
    return {
      total: 0,
      listLoading: false,
      tableData: [],
      listQuery: {
        page: 1,
        limit: 10,
        sort: '-id',
        where: [
          { field: 'status', op: 'eq', value: 4 }
        ]
      }
    }
  },

  created() {
    this.getList()
  },

  methods: {
    getList() {
      this.listLoading = true
      list(this.listQuery).then(response => {
        this.tableData = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },

    handleEdit(index, row) {
      this.$confirm('确定发货吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$set(row, 'loading', true)
        send({
          id: row.id,
          type: 1,
          info: ''
        }).then(res => {
          if (res.status > 0) {
            this.$message.success('操作成功')
            this.tableData.splice(index, 1)
          } else {
            this.$message.error(res.msg)
          }
          this.$set(row, 'loading', false)
        }).catch(e => {
          console.log(e)
          this.$set(row, 'loading', false)
        })
      })
    }
  }
}
</script>

<style lang="scss">
</style>
